package cn.yuanqiao.web.controller.cqbc;

import cn.yuanqiao.common.utils.poi.ExcelUtil;
import cn.yuanqiao.common.core.controller.BaseController;
import cn.yuanqiao.common.core.domain.AjaxResult;
import cn.yuanqiao.common.core.page.TableDataInfo;
import cn.yuanqiao.common.annotation.Log;
import cn.yuanqiao.common.enums.BusinessType;
import cn.yuanqiao.cqbc.yqSetPlate.domain.YqSetPlate;
import cn.yuanqiao.cqbc.yqSetPlate.service.YqSetPlateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * 组盘表控制器
 *
 * @author lyk
 * @Date 2022-11-22 16:30:40
 */
@RestController
@RequestMapping("/cqbc/yqSetPlate")
public class YqSetPlateController extends BaseController {


    @Autowired
    private YqSetPlateService yqSetPlateService;

    /**
     * 新增接口
     *
     * @author lyk
     * @Date 2022-11-22
     */
    @Log(title = "新增组盘", businessType = BusinessType.INSERT)
    @PostMapping("/addItem")
    public AjaxResult addItem(@RequestBody YqSetPlate YqSetPlate) {
        return toAjax(yqSetPlateService.add(YqSetPlate));
    }

    /**
     * 编辑接口
     *
     * @author lyk
     * @Date 2022-11-22
     */
    @Log(title = "编辑组盘", businessType = BusinessType.UPDATE)
    @PutMapping("/editItem")
    public AjaxResult editItem(@RequestBody YqSetPlate YqSetPlate) {
        return toAjax(yqSetPlateService.update(YqSetPlate));

    }

    /**
     * 删除接口
     *
     * @author lyk
     * @Date 2022-11-22
     */
    @Log(title = "删除组盘", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete")
    public AjaxResult delete(@RequestParam("id") Long id) {
        return toAjax(yqSetPlateService.delete(id));
    }

    /**
     * 查看详情接口
     *
     * @author lyk
     * @Date 2022-11-22
     */
    @GetMapping(value = "/{ID}")
    @Log(title = "组盘详情", businessType = BusinessType.SELECT)
    public AjaxResult detail(@PathVariable("ID") Long ID) {
        YqSetPlate detail = yqSetPlateService.getById(ID);
        return success(detail);
    }

    /**
     * 查询列表
     *
     * @author lyk
     * @Date 2022-11-22
     */
    @Log(title = "组盘管理列表查询", businessType = BusinessType.SELECT)
    @GetMapping("/list")
    public TableDataInfo list(YqSetPlate YqSetPlate) {
        startPage();
        List<YqSetPlate> list = yqSetPlateService.findListBySpec(YqSetPlate);
        return getDataTable(list);
        //return this.yqSetPlateService.findPageBySpec(YqSetPlate);
    }


    @Log(title = "组盘管理列表导出", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YqSetPlate YqSetPlate)
    {
        //List<YqCarriermanageDetail> list = yqCarriermanageDetailService.findPageBySpec(yqCarriermanageDetailParam);
        List<YqSetPlate> list = yqSetPlateService.findListBySpec(YqSetPlate);
        ExcelUtil<YqSetPlate> util = new ExcelUtil<>(YqSetPlate.class);
        util.exportExcel(response, list, "组盘管理导出数据");
    }
}


